<template>
  <el-config-provider :locale="currentLocale">
    <router-view />
    <ReDialog />
  </el-config-provider>
</template>

<script lang="ts">
import { defineComponent, onMounted } from "vue";
import { ElConfigProvider } from "element-plus";
import { ReDialog } from "@/components/ReDialog";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";
import { useAppStoreHook } from "@/store/modules/app";

export default defineComponent({
  name: "app",
  components: {
    [ElConfigProvider.name]: ElConfigProvider,
    ReDialog
  },
  computed: {
    currentLocale() {
      //return this.$storage.locale?.locale === "zh" ? zhCn : en
      const pureApp = useAppStoreHook();
      return pureApp.globalI18n == "en" ? en:zhCn
    }
  },
  setup() {
    onMounted(async ()=>{
      // 获取系统自定义配置
      const appStore = useAppStoreHook();
      try {
        await appStore.fetchSysCustomConfig();
        console.log('系统配置加载成功');
      } catch (error) {
        console.warn('系统配置加载失败，使用默认配置:', error);
      }
    })
  }
});
</script>
